package com.zzq.common.result;

import com.google.common.collect.ImmutableMap;
import lombok.Data;

@Data
public class ResultData {
    public static final Object EMPTY_DATA = new Object();
    private Integer status;
    private String msg;
    private boolean success;
    private Object data = new Object();
    private long timestamp;


    public ResultData() {

    }

    public ResultData(Integer status, String msg, Object data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public static ResultData success() {
        return new ResultData(1, "", EMPTY_DATA);
    }

    public static ResultData success(Object msg) {
        if (msg instanceof String) {
            return new ResultData(1, (String) msg, msg);
        } else {
            return new ResultData(1, "", msg);
        }
    }

    public static ResultData success(String msg, Object o) {
        return new ResultData(1, msg, o);
    }

    public static ResultData fail() {
        return new ResultData(0, "", EMPTY_DATA);
    }

    public static ResultData fail(String msg) {
        return new ResultData(0, msg, EMPTY_DATA);
    }

    public static ResultData fail(int code, String msg) {
        return new ResultData(code, msg, EMPTY_DATA);
    }


    public static ResultData notAuth() {

        return new ResultData(0, "not_auth", ImmutableMap.of("not_auth", 1));
    }
}
